package com.hmyd.hmyd_android.adapter;

import java.util.List;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.AppBasic;
import com.hmyd.hmyd_android.dto.Recommend;
import com.hmyd.hmyd_android.utils.Utils;
import com.hmyd.hmyd_android.view.RoundImageView;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class RecommendBonusListAdapter extends BaseAdapter{
	
	private Context mContext;
	private List<Recommend> mPlist;
	private LayoutInflater mInflater;

	public RecommendBonusListAdapter(Context context, List<Recommend> plist){
		super();
		
		this.mContext = context;
		this.mPlist = plist;
		mInflater=LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		return mPlist != null ? mPlist.size() : 0;
	}

	@Override
	public Recommend getItem(int position) {
		return mPlist != null ? mPlist.get(position) : null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(mPlist==null || mPlist.get(position)==null){
			return convertView;
		}
		
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.view_recommend_bonus_list_item, null);
			holder = new ViewHolder();
			holder.title = (TextView)convertView.findViewById(R.id.title);
			holder.time = (TextView)convertView.findViewById(R.id.time);
			holder.amount = (TextView)convertView.findViewById(R.id.amount);
			holder.totalRealIncome = (TextView)convertView.findViewById(R.id.totalRealIncome);
			holder.totalExpectIncome = (TextView)convertView.findViewById(R.id.totalExpectIncome);
			holder.hadBeenRewardWallet = (TextView) convertView.findViewById(R.id.hadBeenRewardWallet);
			
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		
		final Recommend recommend = getItem(position);
		if(recommend!=null){
			holder.title.setText(recommend.title);
			
			holder.title.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
//					mContext.startActivity(InvestmentDetailActivity.getIntent(mContext, recommend.itemId));
				}
			});
			
			/*if(recommend.type.equals("shf")){
				holder.type.setText("[首惠丰]");
				holder.type.setTextColor(mContext.getResources().getColor(R.color.home_shf_text));
	    		
	    	}else if(recommend.type.equals("phb")){
	    		holder.type.setText("[普惠保]");
	    		holder.type.setTextColor(mContext.getResources().getColor(R.color.home_phb_text));
	    		
	    	}else if(recommend.type.equals("hht")){
	    		holder.type.setText("[鸿惠通]");
//	    		holder.type.setTextColor(mContext.getResources().getColor(R.color.home_hht_text));
	    		
	    	}else{
	    		holder.type.setText("");
	    	}*/
			
			/*Drawable title_icon;
			
			if(recommend.attribute.equals("bl")){
				title_icon = mContext.getResources().getDrawable(R.drawable.xi_le_ba);
				title_icon.setBounds(0, 0, title_icon.getMinimumWidth(), title_icon.getMinimumHeight());
				holder.title.setCompoundDrawables(null, null, title_icon, null);
			}else if(recommend.attribute.equals("qyd")){
				title_icon = mContext.getResources().getDrawable(R.drawable.xi_le_qi);
				title_icon.setBounds(0, 0, title_icon.getMinimumWidth(), title_icon.getMinimumHeight());
				holder.title.setCompoundDrawables(null, null, title_icon, null);
			}else if(recommend.attribute.equals("rzzl")){
				title_icon = mContext.getResources().getDrawable(R.drawable.xi_le_zu);
				title_icon.setBounds(0, 0, title_icon.getMinimumWidth(), title_icon.getMinimumHeight());
				holder.title.setCompoundDrawables(null, null, title_icon, null);
			}else if(recommend.attribute.equals("ysyl")){
				title_icon = mContext.getResources().getDrawable(R.drawable.xi_le_yu);
				title_icon.setBounds(0, 0, title_icon.getMinimumWidth(), title_icon.getMinimumHeight());
				holder.title.setCompoundDrawables(null, null, title_icon, null);
			}else{
				holder.title.setCompoundDrawables(null, null, null, null);
			}*/
			
			
			/*if(TextUtils.isEmpty(recommend.avatar)){
				holder.icon.setImageResource(R.drawable.touxin);
			}else{
				AppBasic.getBitmapUtils(mContext).display(holder.icon, recommend.avatar);
			}
			
			holder.nick_name.setText(recommend.username);
			
			if(!TextUtils.isEmpty(recommend.realname)){
				String realname = recommend.realname;
				String m = "";
				for(int i=1;i<realname.length();i++){
					m = m+"*";
				}
				
				holder.nick_name.setText(recommend.username+"("+(realname.subSequence(0, 1)+m)+")");
			}*/
			
			holder.time.setText(Utils.getDateStringDay(recommend.investTime));
			holder.amount.setText(recommend.investAmount);
			
			holder.totalRealIncome.setText(recommend.hadBeenRewardAmount);
			holder.totalExpectIncome.setText(recommend.expectRewardAmount);
			holder.hadBeenRewardWallet.setText(Utils.CovertTwoDecimal(recommend.hadBeenRewardWallet));
		}
		
		return convertView;
	}
	
	class ViewHolder{
		public TextView title;
		public TextView time;
		public TextView amount;
		
		public TextView totalRealIncome;
		public TextView totalExpectIncome;
		public TextView hadBeenRewardWallet;
	}
	
}
